package operator.create;

import java.util.concurrent.TimeUnit;

import io.reactivex.Observable;
import io.reactivex.functions.Consumer;
import util.Printer;
import util.RxJavaHelper;
import util.ThreadHelper;

class IntervalOperator {

    public static void main(String[] args) {
//        interval();
        intervalRange();
    }

    static void interval(){
        //固定的时间间隔发射一个无限递增的整数序列,从0开始每次递增1
        Observable.interval(2, TimeUnit.SECONDS)
                .subscribe(new Consumer<Long>() {
                    @Override
                    public void accept(Long aLong) throws Exception {
                        Printer.printThreadName();
                        Printer.print(aLong);
                    }
                });
//        Observable.interval(10, 2 ,TimeUnit.SECONDS);
//        Observable.interval(10, 2 ,TimeUnit.SECONDS, Schedulers.io());
//        Observable.interval(10, 2 ,TimeUnit.SECONDS, Schedulers.trampoline());
        ThreadHelper.sleep();
    }

    static void intervalRange(){
        //起始值，发送总数量
        Observable.intervalRange(1,5, 5, 2, TimeUnit.SECONDS)
                .subscribe(RxJavaHelper.getConsumer());
        ThreadHelper.sleep();
    }

}
